layui.use(['layer', 'form', 'admin', 'ax','rate'], function () {
    var $ = layui.$;
    var $ax = layui.ax;
    var admin = layui.admin;
    var form = layui.form;
    var rate = layui.rate;

    admin.iframeAuto();

    var star = $("input[name='star']").val()
    rate.render({
        elem: '#star',
        length:3,
        value: star,
        setText: function(value) {
            var arrs = {
                '1': '差'
                , '2': '中等'
                , '3': '好'
            };
            this.span.text(arrs[value] || ( value + "星"));
        },
        choose: function(value){
            //获取id
            $("input[name='star']").val(value)
            var dataScore =  $("input[name='dataScore']").val();
            var score = dataScore*(value/3);
            $("#score").val(score.toFixed(1));
        }
    })

    form.on("submit(btnSubmit)",function (data) {
        var dataScore =  $("input[name='dataScore']").val();
        var score = $("input[name='score']").val();
        if(score>dataScore){
            Feng.error("评分不能大于评判分")
            return;
        }

        var ajax = new $ax(Feng.ctxPath + "/score/updateScore", function (data) {
            Feng.success("评分成功");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("评分失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    })
})